package com.example.hhhh;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.hhhh.fragment.BlankFragment;

/**
 * @ProjectName: Hhhh
 * @Package: com.example.hhhh
 * @ClassName: FiveAct
 * @Description: java类作用描述
 * @Author: songhua
 * @CreateDate: 2020/3/19 0019 15:40
 */
@Route(path = "/app/FiveAct")
public class FiveAct extends SwipeBackActivity {
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private MainPagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_five);
        ARouter.getInstance().inject(this);
        mTabLayout = (TabLayout) findViewById(R.id.tablayout);
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        initView();

    }

    private void initView() {
        for (int i = 0; i < 11; i++) {
            //为TabLayout添加10个tab并设置上文本
            mTabLayout.addTab(mTabLayout.newTab().setText("Tab " + i));
        }

        mAdapter = new MainPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);
        //官方推荐的绑定ViewPager方式
        mTabLayout.setupWithViewPager(mViewPager);
    }


    //ViewPager适配器  10个Fragment
    private class MainPagerAdapter extends FragmentPagerAdapter {
        public MainPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return BlankFragment.newInstance(position);
        }

        @Override
        public int getCount() {
            return 10;
        }
    }



}
